<template>
    <div class="addressSelect">
        <div class="head">
            <van-nav-bar
            title="地址管理"
            left-text="返回"
            left-arrow
            @click-left="onClickLeft"
            />
        </div>
        <div class="contentbox">
            <div class="addresslist" >
                <div class="details"> 
                    <div v-for="item in addresslist" :key="item.id">              
                        <div class="item" @click="select(item.id)">
                            <div class="user">
                            <p>{{item.name}}</p>
                            <div class="moren" v-if="item.is_default==1">默认</div>
                            </div>
                            <div class="info">
                                <p>{{item.mobile}}</p>
                                <p>{{item.address}} {{item.address_detail}}</p>
                            </div>
                            <div class="arrow" @click="editAddress(item.id)"></div>
                        </div>
                   </div>   
                </div>
            </div>
        </div>
        <div class="btm">   
            <div class="add" @click="addAddress"> +新建地址 </div>
        </div>
    </div>
</template>

<script>
 import {getListAction} from "@/api/address"
    export default {
        data() {
            return {
                addresslist:[]
            }
        },
        methods: {
            onClickLeft(){
                this.$router.go(-1);
            },
            addAddress(){
                this.$router.push({
                    path:'/addressEdit'
                })
            },
            editAddress(id){
                this.$router.push({
                    path:'/addressEdit',
                    query:{id:id}
                })
            },
            select(id){
                this.$store.commit('selectAddress',id);
                this.$router.go(-1)
            }
        },
        created(){
            getListAction({
                openId:localStorage.getItem('openId')
            }).then((res) => {
                console.log(res);
                this.addresslist=res.data
            })
        },
        
    }
</script>

<style lang="scss" scoped>
.head {
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 9;
}
.contentbox {
    margin-top: 50px;
    background-color: #eee;
}

.addresslist{
    
    padding-bottom: 50px;
    overflow: hidden;
}
.btm{
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 50px;
    background-color: #fff;
    z-index: 9;

    .add{
        width: 90%;
        height: 35px;
        line-height:35px;
        text-align: center;
        border: 1Px solid #b4282d;
        color: #b4282d;
        margin: 7.5px auto;
    }
}
.moren{
    width: 30px;
    height: 15px;
    border: 1Px solid #b4282d;
    text-align: center;
    line-height: 15px;
    color: #b4282d;
    margin: 1px auto 0 auto;
}
.details{
    padding: 15px 0;
    background-color: #fff;
    margin-bottom: 50px;
    
    .item{
        width: 100%;
        height: 98px;
        position: relative;
        transition: all .3s ease;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 15px 0;
        border-bottom: 1px solid rgba($color: #000000, $alpha: .4);
       

        .user{
            // width: 100%;
            text-align: center;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            align-self: center;
            margin: 0 10px;

            
        }
        .info {
            padding: 0 10px;
            flex: 1;
            text-align: left;
            p{
                text-indent: 2em;
            }
           
        }
        .arrow{
            width: 25px;
            height: 25px;
            margin: 0 10px;
            background: url('../../../assets/images/edit.png') no-repeat center;
            background-size: cover;
        }
    }
}

</style>